<template>
  <div style="padding:20px">
    <div style="margin-bottom: 30px">新增图书</div>
    <el-form :inline="true" :rules="rules" ref="ruleForm" :model="form" label-width="100px">
      <el-form-item label="名称" prop="name">
        <el-input v-model="form.name" placeholder="请输入名称"></el-input>
      </el-form-item>

      <el-form-item label="描述" prop="description">
        <el-input style="width:206px" type="textarea" v-model="form.description" placeholder="请输入描述"></el-input>
      </el-form-item>

      <el-form-item label="出版日期" prop="publishDate">
        <el-date-picker
            v-model="form.publishDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择日期">

        </el-date-picker>
      </el-form-item>

      <el-form-item label="作者" prop="author">
        <el-input v-model="form.author" placeholder="请输入作者"></el-input>
      </el-form-item>

      <el-form-item label="出版社" prop="publisher">
        <el-input v-model="form.publisher" placeholder="请输入出版社"></el-input>
      </el-form-item>

      <el-form-item label="分类" prop="category">
        <el-input v-model="form.category" placeholder="请输入分类"></el-input>
      </el-form-item>

      <el-form-item label="标准码" prop="bookNo">
        <el-input v-model="form.bookNo" placeholder="请输入标准码"></el-input>
      </el-form-item>

      <el-form-item label="封面" prop="cover">
        <el-input v-model="form.cover" placeholder="请输入封面"></el-input>
      </el-form-item>
    </el-form>

    <div style="text-align:center;margin-top:30px">
      <el-button type="primary" @click="save" size="medium">提交</el-button>
<!--      <el-button type="danger">返回列表</el-button>-->
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";
export default {
  name: "AddBook",
  data(){
    return{
      form:{},
      rules: {
        name: [
          {required: true, message: '请输入图书名称', trigger: 'blur'}
        ]
      }
    }
  },
  methods: {
    save(){
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
          //  save方法用于提交数据
          request.post('/book/save',this.form).then(res => {
            if (res.code === '200'){
              this.$notify.success('新增成功')
              //  新增成功后resetFields清空输入框内数据
              this.$refs['ruleForm'].resetFields();
            } else{
              this.$notify.error(res.msg)
            }
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>